package com.wcs.exam.controller.api;

import com.wcs.exam.common.base.Result;
import com.wcs.exam.controller.api.biz.ApiLoginBiz;
import com.wcs.exam.controller.api.req.*;
import com.wcs.exam.controller.api.resp.ApiLoginResp;
import com.wcs.exam.controller.api.resp.ApiLoginWxCodeResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.web.bind.annotation.*;

/**
 * Api-用户信息
 *
 * @author wcs
 * @since 2024-07-06
 */
@Tag(name = "Api-用户登录注册相关接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/api/login")
public class ApiLoginController {

    @NotNull
    private final ApiLoginBiz biz;

    @Operation(summary = "手机验证码发送接口")
    @GetMapping(value = "/send/code")
    public Result<String> sendCode(@RequestParam String mobile) {
        return biz.sendCode(mobile);
    }

    @Operation(summary = "注册接口，成功返回登录信息")
    @PostMapping(value = "/register")
    public Result<ApiLoginResp> register(@RequestBody ApiLoginRegisterReq req) {
        return biz.register(req);
    }

    @Operation(summary = "密码登录接口")
    @PostMapping(value = "/password")
    public Result<ApiLoginResp> password(@RequestBody ApiLoginPasswordReq req) {
        return biz.password(req);
    }

    @Operation(summary = "密码重置接口")
    @PostMapping(value = "/password/reset")
    public Result<String> passwordReset(@RequestBody ApiLoginPasswordResetReq req) {
        return biz.passwordReset(req);
    }

    @Operation(summary = "微信登录，获取授权地址")
    @PostMapping(value = "/wx/auth")
    public Result<String> wxLogin(@RequestBody ApiLoginWxLoginReq req) {
        return biz.wxAuth(req);
    }

    @Operation(summary = "微信登录，获取登录信息")
    @PostMapping(value = "/wx/code")
    public Result<ApiLoginWxCodeResp> wxCode(@RequestBody ApiLoginWxCodeReq req) throws WxErrorException {
        return biz.wxCode(req);
    }

    @Operation(summary = "微信登录，绑定用户信息")
    @PostMapping(value = "/wx/binding")
    public Result<ApiLoginResp> wxBinding(@RequestBody ApiLoginWxBindingReq req) {
        return biz.wxBinding(req);
    }
}
